package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.UserChannelT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;

/**
 * 用户渠道表
 * @author sw
 * @date 2024/6/10 9:49
 */
@MapperScan
public interface UserChannelTMapper {

    @Select("select top 1 * from UserChannel_T where UserId = #{userId} and ServiceChannel = #{serviceChannel} and Flag = 0")
    UserChannelT getUserChannelByUserIdAndChannel(@Param("userId")Long userId, @Param("serviceChannel")String serviceChannel);

    @Select("select * from UserChannel_T where UserId = #{userId} and Flag = 0 order by CreateTime asc")
    List<UserChannelT> getUserChannelListByUserId(@Param("userId")Long userId);

    @Select("select top 1 UserId from UserChannel_T where ExternalUserId = #{externalUserId} and ServiceChannel = #{serviceChannel} and Flag = 0")
    Long getUserChannelByExternalUserIdAndChannel(@Param("externalUserId")String externalUserId, @Param("serviceChannel")String serviceChannel);

    int insert(UserChannelT userChannelT);

    int update(UserChannelT userChannelT);

    int delete(@Param("userId")Long userId,@Param("serviceChannel")String serviceChannel,@Param("time")String time);

    int deleteAll(@Param("userId")Long userId,@Param("time")String time);
}
